<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <a download="tu"  href="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic3.zhimg.com%2F50%2Fv2-2e6e0a328a4b1910b241aab400b9e33c_hd.jpg&refer=http%3A%2F%2Fpic3.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653640468&t=eee4dcece91abb6872da458f4e86d61d">下载</a>
</body>
<script src="./leetcode移动0.js"></script>α
<script src="./jsbasic/object.js"></script>

<script type="module">
    import {Mpromise} from './jsbasic/promise.js'

   let m1 =  new Mpromise((res, rej)=> {
            res(1)
    })
    m1.then((val)=> {
        console.log( val, 1)
    })
    console.log( m1, 2)
    m1.then(
        (val)=> {
        console.log( val, 3)
        }
    )
    let m2 = Mpromise.reject(true) ;
    m2.then(console.log) ;
    var countSmaller = function(nums) {
let res = new Array(nums.length).fill(0) ;
 let temp = [], inds = res.map((v,i)=> i) ;
 let count  = 0 
    function merge(l, r,arr){
    debugger

        count ++ 
        if ( count > 10){ return}
        if (r -l < 1){
            return   
        }
     

        // let mid = ((r- l) >> 1) + l ;
        let mid = ((r+ l) >> 1)  ;
        console.log( l,mid,r)
        let  h1 = l, h2 = mid +1 ;
        merge( l, mid, arr) ;
        merge(  mid+ 1, r,arr) ;
        let temp = []
        /* 要求右侧小于当前元素的个数， */
        while(h1 <=mid ||  h2 <= r){
            /* 等于在谁那边就是在等于的情况谁先进去， 如此一来，后进的那个元素就不能保证一定大于已经在temp里的元素了 */
            if (  h1 <=mid && (arr[h1] <= arr[h2] || h2 > r)){
                /* 此时剩下的数都大于当前数，已经在temp里的右侧的数全部小于当前数 */
                res[h1]+= (h2 -mid -1)
                temp.push( arr[h1++])
            }else if (h2 <= r && (arr[h1] > arr[h2] || h1 > mid)  ){
                temp.push( arr[h2++])
            }
        }
        for ( let i = h1; i<=r; i++){
            arr[i] = temp[i-h1]
        }
        temp = null ;
    }
    merge(0, nums.length -1, nums)
    return  res 
};
// countSmaller([5,2,6,1])
</script>
</html>